<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>YQL Query</title>
    <link rel="stylesheet" href="http://yui.yahooapis.com/3.4.0pr3/build/cssgrids/grids-min.css">
    <link rel="stylesheet" href="../assets/css/main.css">
    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
    <script src="../../build/yui/yui-min.js"></script>
</head>
<body>

<div id="doc">
    <h1>YQL Query</h1>

    
        <a href="#toc" class="jump">Jump to Table of Contents</a>
    

    <div class="yui3-g">
        <div id="main" class="yui3-u">
            <div class="content"><div class="intro">
<img alt="" style="float: right; margin-left: 15px; border: 1px solid #D9D9D9;" src=
"http://l.yimg.com/a/i/us/pps/yql128.gif"> 
 
<p><a href="http://developer.yahoo.com/yql/">The Yahoo! Query Language</a> (YQL) is an expressive SQL-like
language that lets you query, filter, and join data across
Web services. With YQL, <i>apps run faster with fewer lines
of code and a smaller network footprint.</i></p> 
 
<p>Yahoo! and other websites across the Internet make much
of their structured data available to developers, primarily
through Web services. To access and query these services,
developers traditionally endure the pain of locating the
right URLs and documentation to access and query each Web
service.</p> 
 
<p>With YQL, developers can access and shape data across
the Internet through one simple language, eliminating the
need to learn how to call different APIs.</p> 
</div>

<h2 id="getting-started">Getting Started</h2>

<p>
To include the source files for YQL Query and its dependencies, first load
the YUI seed file if you haven't already loaded it.
</p>

<pre class="code prettyprint">&lt;script src=&quot;http:&#x2F;&#x2F;yui.yahooapis.com&#x2F;3.4.0&#x2F;build&#x2F;yui&#x2F;yui-min.js&quot;&gt;&lt;&#x2F;script&gt;</pre>


<p>
Next, create a new YUI instance for your application and populate it with the
modules you need by specifying them as arguments to the <code>YUI().use()</code> method.
YUI will automatically load any dependencies required by the modules you
specify.
</p>

<pre class="code prettyprint">&#x2F;&#x2F; Create a new YUI instance and populate it with the required modules.
YUI().use(&#x27;yql&#x27;, function (Y) {
    &#x2F;&#x2F; YQL Query is available and ready for use. Add implementation
    &#x2F;&#x2F; code here.
});</pre>


<p>
For more information on creating YUI instances and on the
<a href="http://yuilibrary.com/yui/docs/api/classes/YUI.html#method_use"><code>use()</code> method</a>, see the
documentation for the <a href="../yui/index.html">YUI Global object</a>.
</p>


<h2 id="query">Making a Query</h2>
<p>After you find the query you want to run in the Developer Console, just plug it in:</p>
<p>The <a href="http://developer.yahoo.com/yql/console/">YQL Developer Console</a> is a nice place to start playing with YQL queries. You can test and inspect queries before you actually use them.</p>

<pre class="code prettyprint">YUI().use(&#x27;yql&#x27;, function(Y) {

    Y.YQL(&#x27;select * from weather.forecast where location=90210&#x27;, function(r) {
        &#x2F;&#x2F;r now contains the result of the YQL Query
		&#x2F;&#x2F;use the YQL Developer console to learn
		&#x2F;&#x2F;what data is coming back in this object
		&#x2F;&#x2F;and how that data is structured.
    });

});</pre>



<h2 id="query-reuse">Re-Using A Query</h2>
<p>Modifying the example above to make it reusable is simple, just save the result of the query and call <code>send</code> on it to query for the results again.</p>

<pre class="code prettyprint">YUI().use(&#x27;yql&#x27;, function(Y) {

    var q = Y.YQL(&#x27;select * from weather.forecast where location=90210&#x27;, function(r) {
        &#x2F;&#x2F;r now contains the result of the YQL Query
    });

    &#x2F;&#x2F;Sometime later

    q.send();

});</pre>



<h2 id="changing-a-re-used-query">Changing A Re-Used Query</h2>
<p>Changing a query without creating a new instance can be beneficial for queries that involve the same request but different parameters (like an AutoComplete query).</p>
<p>To do this, we need to modify the private param <code>q</code> on the YQL instance.</p>

<pre class="code prettyprint">YUI().use(&#x27;yql&#x27;, function(Y) {

    var q = Y.YQL(&#x27;select * from weather.forecast where location=90210&#x27;, function(r) {
        &#x2F;&#x2F;r now contains the result of the YQL Query
    });

    &#x2F;&#x2F;Sometime later
    q._params.q = &#x27;select * from weather.forecast where location=62959&#x27;;
    q.send();

});</pre>


<h2 id="tables">Open Data Tables</h2>
<p>Open Data Tables enable developers to add tables for any data on the Web to YQL's stable of API-specific tables. Using Open Data Tables, anyone can make their data YQL-accessible. If you would like to create an Open Data Table, visit the community page at <a href="http://datatables.org">http://datatables.org</a>.</p>
<p>By default, the <code>YQL</code> module will include the environment file needed to use all of the publicly available Open Data Tables.</p>

<h2 id="advoptions">Advanced Options</h2>
<p>The default configuration for the <code>YQL</code> module is designed for the most basic use cases. However, the <code>YQLRequest</code> class is designed to give the developer more control over the query, parameters and options used to make the YQL Request.</p>

<pre class="code prettyprint">YUI().use(&#x27;yql&#x27;, function(Y) {

    var q = new Y.YQLRequest(&#x27;select * from weather.forecast where location=90210&#x27;, function(r) {
        &#x2F;&#x2F;r now contains the result of the YQL Query
    }, {
        &#x2F;&#x2F;Optional URL Parameters to add to the request
        foo: &#x27;bar&#x27;,
        another: &#x27;option&#x27;
    }, {
        &#x2F;&#x2F;Options
        base: &#x27;:&#x2F;&#x2F;query.yahooapis.com&#x2F;v1&#x2F;yql?&#x27;, &#x2F;&#x2F;Different base URL for private data
        proto: &#x27;https&#x27; &#x2F;&#x2F;Connect using SSL
    });
    q.send();

});</pre>

</div>
        </div>

        <div id="sidebar" class="yui3-u">
            
                <div id="toc" class="sidebox">
                    <div class="hd">
                        <h2 class="no-toc">Table of Contents</h2>
                    </div>

                    <div class="bd">
                        <ul class="toc">
<li>
<a href="#getting-started">Getting Started</a>
</li>
<li>
<a href="#query">Making a Query</a>
</li>
<li>
<a href="#query-reuse">Re-Using A Query</a>
</li>
<li>
<a href="#changing-a-re-used-query">Changing A Re-Used Query</a>
</li>
<li>
<a href="#tables">Open Data Tables</a>
</li>
<li>
<a href="#advoptions">Advanced Options</a>
</li>
</ul>
                    </div>
                </div>
            

            
                <div class="sidebox">
                    <div class="hd">
                        <h2 class="no-toc">Examples</h2>
                    </div>

                    <div class="bd">
                        <ul class="examples">
                            
                                
                                    <li data-description="Create a simple YQL Query to retrieve data from the Yahoo! Weather YQL table.">
                                        <a href="simple-yql.html">Simple YQL Query</a>
                                    </li>
                                
                            
                                
                                    <li data-description="Use the Flickr Recent Photos YQL table to pull in a small set of recent Flickr images every 8 seconds.">
                                        <a href="yql-requery.html">Reusing a YQL query</a>
                                    </li>
                                
                            
                                
                            
                                
                            
                        </ul>
                    </div>
                </div>
            

            
                <div class="sidebox">
                    <div class="hd">
                        <h2 class="no-toc">Examples That Use This Component</h2>
                    </div>

                    <div class="bd">
                        <ul class="examples">
                            
                                
                            
                                
                            
                                
                                    <li data-description="Example Photo Browser application.">
                                        <a href="../dd/photo-browser.html">Photo Browser</a>
                                    </li>
                                
                            
                                
                                    <li data-description="Portal style example using Drag &amp; Drop Event Bubbling and Animation.">
                                        <a href="../dd/portal-drag.html">Portal Style Example</a>
                                    </li>
                                
                            
                        </ul>
                    </div>
                </div>
            
        </div>
    </div>
</div>

<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script>prettyPrint();</script>

</body>
</html>
